package com.chenfan.mcn.exception;

import com.chenfan.common.exception.ResultState;
import com.chenfan.common.exception.SystemState;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author lizhejin
 */
@Getter
public enum McnErrorCode implements ResultState {

    /**************************【系统-公共错误码】**************************/
    // 操作失败
    FAILED(-1, "操作失败", true),
    // 操作成功
    SUCCESS(0, "操作成功"),
    //200-操作成功（老的）
    SUCCESS_OLD(SystemState.SUCCESS.code(), "操作成功"),
    //500-系统繁忙，请稍后再试
    ERROR(SystemState.ERROR.code(), SystemState.ERROR.message(), true),
    //10001-网络繁忙，请稍后再试
    API_GATEWAY_ERROR(SystemState.API_GATEWAY_ERROR.code(), SystemState.API_GATEWAY_ERROR.message(), true),
    //10002-网络出问题，请稍后再试
    RPC_ERROR(SystemState.RPC_ERROR.code(), SystemState.RPC_ERROR.message(), true),
    //10003-网络拥挤，请稍后再试
    TRAFFIC_LIMITING(SystemState.TRAFFIC_LIMITING.code(), SystemState.TRAFFIC_LIMITING.message(), true),
    //10004-服务不可用自动降级
    SERVICE_DEGRADE(SystemState.SERVICE_DEGRADE.code(), SystemState.SERVICE_DEGRADE.message(), true),
    //用户没有接口权限
    NO_URL_AUTH(100101, "用户没有接口权限", true),
    //20001-业务异常
    BUSINESS_ERROR(SystemState.BUSINESS_ERROR.code(), SystemState.BUSINESS_ERROR.message()),
    //20002-参数错误
    PARAM_ERROR(SystemState.PARAM_ERROR.code(), SystemState.PARAM_ERROR.message()),

    //20003-操作太频繁，请稍后再试
    LOCK_TRIGGER(20003, "操作太频繁, 请稍后再试"),

    // 无访问权限
    UNAUTHORIZED(30001, "无访问权限"),
    NO_AUTHORIZATION_TOKEN(30002, "无访问权限标识", false),
    NO_PRIVILEGE_CODE(30003, "无数据权限标识", false),

    /**
     * 微服务接口调用错误码
     */
    CLIENT_RESPONSE_NO_RESULT(30010, "调微服务接口响应-无结果", true),
    CLIENT_RESPONSE_NOT_DATA(30011, "调微服务接口响应-无数据", true),
    CLIENT_RESPONSE_FAILED(30012, "调微服务接口响应-操作失败", true),

    /**************************【业务-公共错误码】**************************/

    /**
     * 审批流相关错误码
     */
    FLOW_ERROR(80001, "审批流程出错", true),
    FLOW_NOT_FOUND(80002, "审批流程不存在"),
    FLOW_SAVE_ERROR(80003, "审批流保存异常", true),
    FLOW_SUBMITTER_NULL(80004, "审批流提起人不能为空"),
    FLOW_CALLBACK_HANDLE_EXCEPTION(80005, "审批流回调处理异常", true),
    FLOW_SAVE_DUPLICATE(80006, "已存在流程，提交失败", true),
    FLOW_CALLBACK_METHOD_NOT_FOUND(80007, "对应回调方法不存在", true),
    FLOW_LACK_CONFIGURATION_ERROR(80008, "审批流分支未配置，请先联系产品运营正确配置审批流！", true),
    FLOW_FINISHED(80009, "审批流程已结束"),

    /**
     * 通用数据操作错误码
     */
    USER_INFO_ERROR(80010, "用户信息获取异常"),
    DATA_INSERT_ERROR(80019, "新增失败"),
    DATA_NOT_FOUND(80020, "查询不到数据"),
    DATA_EXISTED(80021, "数据已存在"),
    DATA_IS_DELETED(80022, "数据已删除"),
    DATA_ILLEGAL(80023, "非法数据"),
    DATA_INVALID(80024, "无效数据"),
    DATA_FOUND_MULTIPLE(80025, "查到多条数据"),
    DATA_UNAUTH_ACCESS(80026, "无权限访问数据"),
    DATA_UNDEFINE(80027, "未定义异常"),
    DATA_OPERATION_NOT_SUPPORTED(80028, "不支持该操作"),
    DATA_REPETITIVE_OPERATION(80029, "重复操作"),
    OLD_DATA(80030, "历史数据暂不支持查看"),
    CUSTOMER_ID_NOT_EXIST(80031, "客户id:%s 不存在"),
    REMIND_DUPLICATE_ENTRY(80032, "重复数据录入"),

    /**
     * 导入导出相关相关
     */
    EXPORT_HAS_NO_DATA(80050, "当前条件下无数据可导出"),
    EXPORT_EXCEPTION(80051, "导出异常"),
    EXPORT_FILE_ID_ILLEGAL(80052, "文件ID格式非法"),
    IMPORT_EXCEL_CANT_BE_EMPTY(80055, "导入Excel文件不能为空"),
    IMPORT_EXCEL_FAILED(80056, "导入Excel失败"),
    IMPORT_CONTENT_EMPTY(80057, "上传内容为空"),
    IMPORT_TEMPLATE_WRONG(80058, "导入模板有误"),
    IMPORT_SIZE_ERROR(80059,"有其他人正在使用这个功能或者导入数据超过系统可以处理能力"),
    IMPORT_ERROR_TIME_OUT(80060,"不存在失败原因或者失败原因文件超过48小时过期了"),
    IMPORT_NUM_ERROR(80061,"导入excel条数超过500"),



    /**
     * 其它
     */
    DICT_TRANSLATION_EXCEPTION(80060, "字典翻译异常"),
    ORDER_FEILD_NOT_EXIST(80061, "该排序字段不存在"),
    ILLEGAL_BILL_CODE(80062, "非法单据号"),
    DUPLICATE_ARCHIVE_NUMBER(80063, "归档编号重复"),
    BILL_CODE_NOT_NULL(80064, "单据号不能为空"),
    ARCHIVING_CODE_NOT_NULL(80065, "归档编号不能为空"),
    CONTRACT_TYPE_NOT_SUPPORTED(80066, "合同类型不支持"),


    /**************************【业务-定制错误码】**************************/

    /**
     * 采购合同
     */
    PURCHASE_NOT_EXISTS(81000, "采购合同不存在"),
    PURCHASE_CANCELED(81001, "采购合同已被撤回"),
    PURCHASE_INVALID(81002, "采购合同已被作废"),
    RELATION_EXECUTION_ORDER(81003, "该合同已关联执行单，请先作废执行单"),
    PURCHASE_VOID_FAILED(81004, "执行单审批中或者审批通过不允许作废采购合同！"),

    /**
     * 日志
     */
    FIELD_CHANGE_LOG_GENERATE_FAIL(81501, "操作日志生成失败"),
    ONLY_CREATOR_CAN_UPDATE(81502, "仅评论创建人可编辑"),
    ONLY_CREATOR_CAN_DELETE(81503, "仅评论创建人可删除"),

    /**
     * 客户返点审批单
     */
    ANNUAL_NOT_EXISTS(82000, "客户返点审批单不存在"),
    ANNUAL_CANCELED(82001, "客户返点审批单已被撤回"),
    ANNUAL_INVALID(82002, "客户返点审批单已被作废"),
    ANNUAL_INVALID_FAIL(82003, "作废失败，请先去【费用管理】作废相应费用"),
    DISCOUNT_APPROVAL_ASSOCIATED(82004, "折扣审批单已被关联，请重新选择"),

    /**
     * 商务提成
     */
    CONTRACT_CANNOT_BE_REPEATED(83000, "合同不可重复添加"),
    EXCUTE_ORDER_CANNOT_BE_REPEATED(83000, "执行单不可重复添加"),
    BUSINESS_INVALID(83001, "商务提成单已被作废"),
    ONLY_ONE_BUSINESS_COMMISSION(83002, "一个季度只能有一个非作废状态的提成单"),
    BUSINESS_COMMISSION_IS_NULL(83003, "商务提成单不存在"),
    BUSINESS_COMMISSION_IS_INVALID(83004, "提成单已作废"),
    BUSINESS_COMMISSION_DETAIL_IS_NULL(83005, "无提成明细数据，发送失败"),
    BUSINESS_COMMISSION_TITLE_REPEATED(83006, "提成单标题不允许重复"),


    /**
     * AE提成
     */
    AE_CANNOT_BE_REPEATED(84000, "AE季度提成单不可重复添加"),
    AE_EXCUTE_CANNOT_BE_REPEATED(84001, "AE提成单[{%s}]不可重复添加"),
    AE_INVALID(84002, "AE提成单已经被作废"),
    AE_QUARTERLY_CODE_IS_NULL(84003, "AE季度提成单编号为空"),
    AE_QUARTERLY_ID_IS_NULL(84004, "AE季度提成单id为空"),
    AE_ID_IS_NULL(84005, "AE提成单id为空"),
    AE_EXCUTE_IS_NULL(84006, "执行单为空,无法关联AE提成单"),
    AE_CANNOT_IS_NULL(84007, "AE季度提成单不存在"),
    AE_CONFIRM_ID_IS_NULL(84008, "AE提成确认id为空"),
    USERS_BUSINESS_COMMISSION_NOT_EXIST(84009, "该用户的商务提成不存在"),
    AE_CONTRACT_ONLY_ONE(84010, "一个月份仅能存在一份非作废状态提成单"),
    AE_DETAIL_IS_NULL(84011, "无提成明细数据，发送失败"),

    // 折扣审批单
    DATE_RANGE_EXISTS(84001, "时间段内已存在折扣审批单"),
    CUSTOMER_HAS_NO_ELIGIBLE_ANNUAL_DISCOUNT(84002, "该客户无符合条件年度优惠折扣返点审批单"),
    CUSTOMER_HAS_ELIGIBLE_ANNUAL_DISCOUNT(84003, "该客户有年度优惠折扣返点审批单，请修改合同类型。"),
    DISCOUNT_NOT_EXISTS(84004, "折扣审批单不存在"),
    DISCOUNT_CANCELED(84005, "折扣审批单已被撤回"),
    DISCOUNT_INVALID(84006, "折扣审批单已被作废"),
    DISCOUNT_APPROVAL_UN_COMMIT_COMMIT_ERROR(84007, "【待提交】状态，仅允许【提交审批、作废】！"),
    DISCOUNT_APPROVAL_UN_COMMIT_CANCEL_ERROR(84008, "【审批中】状态，仅允许【撤回、作废】！"),
    DISCOUNT_APPROVAL_REJECTED_ERROR(84009, "【审批拒绝】状态，仅允许【提交审批、作废】！"),
    DISCOUNT_APPROVAL_CANCEL_ERROR(84010, "【已撤回】状态，仅允许【提交审批、作废】！"),
    DISCOUNT_APPROVA_PASSED_ERROR(84011, "【审批通过】状态，仅允许【作废】！"),
    DISCOUNT_APPROVA_UPDATE_ERROR(84012, "仅待提交、审批拒绝、已撤回允许编辑"),


    //收入合同&收入合同补充协议
    INCOME_NOT_EXISTS(85000, "收入合同不存在"),
    INCOME_CANCELED(85001, "收入合同已被撤回"),
    INCOME_INVALID(85002, "收入合同已被作废"),
    INCOME_VOID_FAILED(85003, "请先作废补充协议"),
    NO_EXECUTION(85004, "收入合同至少要有一条未作废的执行单"),
    EXCEEDING_CONTRACT_AMOUNT(85005, "合同金额须等于执行单总金额之和"),
    EXECUTION_INVALID_FAIL(85006, "请先作废执行单"),
    NO_CALCULATION_DEVIDED(85007, "执行单计算分成信息为空"),
    AGREEMENT_NOT_EXISTS(85008, "收入合同补充协议不存在"),
    AGREEMENT_CANCELED(85009, "收入合同补充协议已被撤回"),
    AGREEMENT_INVALID(85010, "收入合同补充协议已被作废"),
    PLEASE_INVALID_INCOME_CONTRACT_CHARGE(85011, "请先作废收入合同对应费用"),
    NON_VOIDABLE(85012, "不可作废审核通过的收入合同补充协议"),
    AMOUNT_MUST_BE_EQUAL(85013, "合同金额须等于执行单总金额之和"),
    PLATFORM_ORDER_NUMBER_EXIST(85014, "平台订单号已存在"),
    NO_CUSTOMER_SIGN_SUBJECT(85015, "请选择客户签约主体"),
    NO_INVOICE_TYPE(85016, "请选择开票类型"),
    NO_INVOICE_CONTENT(85017, "请填写开票内容"),
    ADD_SYSTEM_CUSTOMER_BILLING_FAILED(85018, "新增客户系统默认开票抬头失败"),
    PLATFORM_ORDER_NUMBER_REPEAT(85019, "平台订单号重复"),
    PLATFORM_ORDER_NUMBER_EXCEEDS_DIGITS(85020, "订单号长度错误，请检查后重试。"),
    SUPPLEMENTARY_AGREEMENT_RELATED_EXECUTION(85021, "补充协议有关联执行单，请先作废执行单。"),
    PLATFORM_ORDER_NUMBER_ONLY_NUMBER(85022, "平台订单号只能为数字"),
    VERIFY_AMOUNT_ERROR(85023, "相关金额输入校验不通过"),
    CALCULATE_EXPECTED_AMOUNT_ERROR(85024, "计算收入合同预估金额异常"),
    EXECUTION_ORDER_CANNOT_BE_DETERMINED(85025, "框架合同类型仅适用于不能确定执行单的合同，请修改合同类型"),
    CUSTOMER_SIGNING_ENTITY_CANNOT_BE_EMPTY(85026, "开票信息的客户签约主体不能为空"),
    AMOUNT_IS_NOT_EQUAL(85027, "直播金额+广告金额需等于商务确认合同金额，请检查后重试"),
    MUST_BE_EQUAL_TO_AD_AMOUNT(85028, "执行单总金额之和须等于广告金额"),
    AGREEMENT_AMOUNT_MUST_BE_EQUAL(85029, "直播金额+广告金额需等于商务确认合同金额，请检查后重试！"),
    ANCHOR_ID_IS_NULL(85030, "主播id不能为空"),
    NO_ALLOW_CHANGE_INVOICE_INFO(85031, "形式合同不允许修改开票信息"),
    PLEASE_INVALID_LIVE_CONTRACT_CHARGE(85032, "修改广告金额须先作废直播合同费【注：非收入合同费】"),
    INCOME_ADD_INTENTION_ORDER_ERROR(85033, "仅允许「已确认、执行中、执行完成」状态的前置执行单创建合同！"),

    FORMAL_INCOME_ONE_INTENTION_ORDER(85034, "散单/年度优惠形式合同仅允许关联一条前置执行单!"),



    /**
     * 年框合同
     */
    NO_VALID_DISCOUNT(86000, "当前客户无有效的折扣返点审批，请重新选择"),
    VOID_FAILED(86001, "存在未作废的年框合同补充协议，作废失败"),
    EXIST_NON_VOID_CONTRACT(86002, "该折扣返点审批单已经关联非作废状态的年框合同，请重新选择"),
    CONTENT_SAME(86003, "变更前后内容不能相同，请重新选择"),
    YEAR_NOT_EXISTS(86004, "年框合同不存在"),
    YEAR_CANCELED(86005, "年框合同已被撤回"),
    YEAR_INVALID(86006, "年框合同已被作废"),
    SUPPLEMENTARY_NOT_EXISTS(86007, "年框合同补充协议不存在"),
    SUPPLEMENTARY_CANCELED(86008, "年框合同补充协议已被撤回"),
    SUPPLEMENTARY_INVALID(86009, "年框合同补充协议已被作废"),
    YEAR_NON_VOIDABLE(86010, "不可作废审核通过的年框合同补充协议"),
    COOPERATION_TIME_REPEAT(86011, "同一客户相同合同类型签约时间不允许重复"),

    /**
     * 执行单
     */
    IMPLEMENTATION_AUDIT_PASSED(87000, "执行单审核通过,不允许作废"),
    EXECUTION_NOT_EXISTS(87001, "执行单不存在"),
    EXECUTION_CANCELED(87002, "执行单已被撤回"),
    EXECUTION_INVALID(87003, "执行单已被作废"),
    EXECUTION_START_NULL(87004, "执行单红人不能为空"),
    INCOME_NOT_APPROVED(87005, "收入合同未审批通过，不能提交执行单"),
    PLEASE_CONNECT_PURCHASE_CODE(87006, "请关联采购单号"),
    INVALID_FAILED(87007, "作废失败，请先去【费用管理】作废相应费用"),
    EXCUTION_TOTAL_AMOUNT_WRONG(87008, "执行单总金额有误"),
    EXECUTION_ORDER_HAS_BEEN_PRINTED(87009, "已打款执行单不能作废"),
    RELATED_AGREEMENT_NOT_PASSED(87010, "收入合同补充协议审批未通过，不能提交执行单"),
    EXECUTION_ORDER_NOT_MATCH_APPROVAL(87010, "执行单类型匹配不到审批流程枚举"),
    EXECUTION_NOT_NULL(87011, "执行单不能为空"),
    SCREENSHOT_PAYMENT_NOT_NULL(87012, "当应收金额输入不为0时，打款截图为必填"),
    YEAR_CODE_NOT_NULL(87013, "当应收金额输入为0时，年框合同必填。"),
    KOC_ACTUAL_QUOTED_PRICE_VERIFY_ERROR(87014, "执行单总金额需等于固定到手价+其他金额之和"),
    KOC_IS_BATCH_REMITTANCE(87015, "结算方式需要为【批量打款】"),
    KOC_PUBLISH_URL(87016, "发布链接必填"),
    FORCED_REJECT_FAILED(87017, "强制驳回失败，请先去【费用管理】作废相应费用"),
    CONTRACT_EXCUTION_ORDER_UN_EXECUTE_ERROR(87018, "【待执行】状态，仅允许【开始执行、作废】！"),
    CONTRACT_EXCUTION_ORDER_EXECUTING_ERROR(87019, "【执行中】状态，仅允许【执行完成、作废】！"),
    CONTRACT_EXCUTION_ORDER_EXECUTED_ERROR(87020, "【已执行】状态，仅允许【提交确认、作废】！"),
    CONTRACT_EXCUTION_ORDER_UN_COMMIT_ERROR(87021, "【审批中】状态，仅允许【撤回、作废】！"),
    CONTRACT_EXCUTION_ORDER_PASSED_ERROR(87022, "【待打款】状态，仅允许【作废、强制驳回】！"),
    CONTRACT_EXCUTION_ORDER_PAID_ERROR(87023, "【已打款】状态，仅允许【作废、强制驳回】！"),
    CONTRACT_EXCUTION_ORDER_REJECTED_ERROR(87024, "【审批拒绝】状态，仅允许【提交审批、作废】！"),
    CONTRACT_EXCUTION_ORDER_CANCEL_ERROR(87025, "【已撤回】状态，仅允许【提交审批、作废】！"),
    CONTRACT_EXCUTION_ORDER_CONFIRMING_ERROR(87026, "【确认中】状态，仅允许【确认、驳回、撤回、作废】！"),
    CONTRACT_EXCUTION_ORDER_CONFIRMED_ERROR(87027, "【已确认】状态，仅允许【提交审批、作废】！"),
    CONTRACT_EXCUTION_ORDER_CONFIRM_REJECTED_ERROR(87028, "【确认驳回】状态，仅允许【提交确认、作废】！"),

    CONTRACT_EXCUTION_ORDER_UPDATE_ERROR(87029, "仅待执行、执行中、已执行、审批拒绝、已撤回允许编辑"),
    CONTRACT_EXCUTION_ORDER_FEE_UPDATE_ERROR(87030, "合同已提交，执行单“总收入(元)”无法修改，请确保修改后总收入金额仍为[%s]元！"),


    EXCUTION_ORDER_EPEATED(87100, "执行完成时提示正式执行单重复"),
    EXCUTION_ORDER_ADD_REPEATED(87200, "录入时提示正式执行单重复"),
    EXCUTION_ORDER_CONTRACT_NO_PASSED(87300, "关联合同或者关联补充协议单据状态非「审批通过」"),
    EXCUTION_NO_AUTH(87400, "非当前单据的执行人（主管）不能操作！"),
    EXCUTION_LEADER_NO_AUTH(87500, "非当前单据的执行人主管不能操作！"),
    /**
     * mq推送
     */
    EXCUTION_ORDER_PUSH_FINANCE_FAILED(88000, "执行单费用推送财务系统失败"),
    INCOME_CONTRACT_PUSH_FINANCE_FAILED(88001, "收入合同费用推送财务系统失败"),
    INCOME_CONTRACT_AGREEMENT_PUSH_FINANCE_FAILED(88002, "收入合同补充协议费用推送财务系统失败"),
    YEAR_REBATE_CHARGE_PUSH_FINANCE_FAILED(88003, "年度返点审批单费用推送财务系统失败"),


    /**
     * 目标管理相关
     */
    COMPANY_TARGET_EXIST(89100, "该季度目标已存在"),
    DEPARTMENT_TARGET_EXIST(89101, "该季度目标已存在"),
    DEPARTMENT_TARGET_NOT_EXIST(89102, "部门目标不存在"),
    COMPANY_TARGET_NOT_EXIST(89103, "公司目标不存在"),
    PLEASE_CHOOSE_QUARTER_CODE(89104, "请选择季度编号"),
    CUSTOMER_TARGET_EXIST(89105, "该季度目标已存在"),
    CUSTOMER_CAN_NOT_REPEAT(89106, "客户不能重复"),
    CUSTOMER_TARGET_NOT_EXIST(89107, "客户目标不存在"),
    PLEASE_CHOOSE_CUSTOMER(89108, "请指定客户"),
    PLEASE_CHOOSE_MONTHLY_CODE(89109, "请选择月度编号"),
    MONTHLY_TARGET_NOT_EXIST(89110, "月度部门目标不存在"),
    MONTHLY_TARGET_EXIST(89111, "该月度目标已存在"),

    /**
     * 意向单
     */
    INTENTION_ORDER_EXIST_INCOME_CONTRACT(89150,"意向单已关联收入合同，请问是否继续！"),
    INTENTION_ORDER_CAN_NOT_UPDATE(89151,"待AE主管确认||已完结||已拒单||已作废不允许编辑！"),
    NOT_ALLOWED_BATCH_ACCEPT_ORDER(89152,"存在询单问题不允许批量接单！"),

    /**
     * 红人相关
     */
    DUPLICATE_CELEBRITY_NICKNAME(89200, "红人昵称重复，红人已存在"),
    DUPLICATE_ID_NUMBER(89201, "红人身份证号重复，请检查后重试！"),
    NOT_ALLOWED_CHANGE_STAR_TYPE(89202, "已关联执行单，不允许修改红人类型"),
    SIGN_CONTRACT_EXISTED(89203, "红人签约合同编号已存在"),
    ALIPAY_ACCOUNT_LENGTH(89204, "支付宝账号超长"),
    ALIPAY_ACCOUNT_REPEAT(89205, "红人签约合同编号重复"),
    STAR_BASIC_DATA_IS_NULL(89206, "红人信息不存在"),
    STAR_ACCOUNT_BASIC_DATA_IS_NULL(89206, "红人账户信息不存在"),

    STAR_PLATOFRM_INFO_IS_NULL(89206, "红人平台信息不存在"),

    KOCPMNAME_EXISTS(89207, "项目名称不允许重复"),
    TARFGET_STAR_ACCOUNT_BASIC_DATA_IS_NULL(89208, "%s->红人账户信息不存在"),
    TARFGET_EXCUTION_ORDER_IS_NULL(89209, "%s->执行单信息不存在"),
    KOC_STAR_TYPE_NOT_ALL_ERROR(89210, "无信息确认截图，无法提交审批流，请先创建月度结算单"),
    TARFGET_EXCUTION_ORDER_SETTLE_ONLINE_ERROR(89211, "%s->至少需要一条执行单的结算方式为线上结算单"),

    STAR_MONTHLY_SETTLEMENT_UN_COMMIT_ERROR(89212, "【待提交】状态，仅允许【提交审批、作废】！"),
    STAR_MONTHLY_SETTLEMENT_APPROVAL_ERROR(89213, "【审批中】状态，仅允许【撤回、作废】！"),
    STAR_MONTHLY_SETTLEMENT_UN_PAYBACK_ERROR(89214, "【待打款】状态，仅允许【作废】！"),
    STAR_MONTHLY_SETTLEMENT_REJECTED_ERROR(89215, "【审批拒绝】状态，仅允许【提交审批、作废】！"),
    STAR_MONTHLY_SETTLEMENT_CANCEL_ERROR(89216, "【已撤回】状态，仅允许【提交审批、作废】！"),
    STAR_MONTHLY_SETTLEMENT_PART_PAYBACK_ERROR(89217, "【部分打款】状态，仅允许【作废】！"),
    STAR_MONTHLY_SETTLEMENT_ALL_PAYBACK_ERROR(89218, "【已打款】状态，仅允许【作废】！"),


    ANNUAL_REBATE_UN_COMMIT_ERROR(89219, "【待提交】状态，仅允许【提交审批、作废】！"),
    ANNUAL_REBATE_APPROVAL_ERROR(89220, "【审批中】状态，仅允许【撤回、作废】！"),
    ANNUAL_REBATE_WAITING_PAYMENT_ERROR(89221, "【待打款】状态，仅允许【作废】！"),
    ANNUAL_REBATE_REJECTED_ERROR(89222, "【审批拒绝】状态，仅允许【提交审批、作废】！"),
    ANNUAL_REBATE_CANCEL_ERROR(89223, "【已撤回】状态，仅允许【提交审批、作废】！"),
    ANNUAL_REBATE_PAID_ERROR(89224, "【已打款】状态，禁止操作！"),

    STAR_REBATE_CONTRACT_UN_COMMIT_ERROR(89225, "【待提交】状态，仅允许【提交审批、作废】！"),
    STAR_REBATE_CONTRACT_APPROVAL_ERROR(89226, "【审批中】状态，仅允许【撤回、作废】！"),
    STAR_REBATE_CONTRACT_UN_PAYBACK_ERROR(89227, "【待回款】状态，仅允许【作废】！"),
    STAR_REBATE_CONTRACT_REJECTED_ERROR(89227, "【审批拒绝】状态，仅允许【提交审批、作废】！"),
    STAR_REBATE_CONTRACT_CANCEL_ERROR(89227, "【已撤回】状态，仅允许【提交审批、作废】！"),
    STAR_REBATE_CONTRACT_PART_PAYBACK_ERROR(89227, "【部分回款】状态，仅允许【作废】！"),
    STAR_REBATE_CONTRACT_ALL_PAYBACK_ERROR(89227, "【已回款】状态，仅允许【作废】！"),

    DUPLICATE_PLATFORM_SETTLEMENT_COOPERATION_CONTENT(89228,"同一平台下合作内容不允许重复"),

    GEN_CODE_FAIL(89212,"取号失败", true),

    /**直播场次*/
    DELETE_ERROR_HAVE_COMMODITY(89600,"含有未删除商品，直播场次删除失败！"),
    AMOUNT_OF_THE_EXECUTIO_NMUST_BE_EQUAL(89601,"执行单总金额之和需要等于参与保比广告收入+不参与保比广告收入之和！"),
    MUST_BE_ONE_ORDER_WITH_THE_AMOUNT_ZERO(89602,"有广告权益时即使金额为0也必须创建金额为0的对应执行单！"),
    INTENT_HAS_ALREADY_BEEN_LINKED_BY_OTHER(89603,"前置执行单已经被其他执行单和收入合同关联了！"),
    ;

    private final int code;
    private String message;
    private boolean mustAlarm;
    private String messageFormat;

    McnErrorCode(int code, String message) {
        this.code = code;
        this.message = message;
        this.mustAlarm = false;
    }

    McnErrorCode(int code, String message, boolean mustAlarm) {
        this.code = code;
        this.message = message;
        this.mustAlarm = mustAlarm;
    }

    public McnErrorCode format(String key) {
        this.messageFormat = String.format(this.message, key);
        return this;
    }

    @Override
    public int code() {
        return this.code;
    }

    @Override
    public String message() {
        return StringUtils.isBlank(this.messageFormat) ? this.message : this.messageFormat;
    }

    public static McnErrorCode toEnum(int code) {
        for (McnErrorCode item : McnErrorCode.values()) {
            if (item.code == code) {
                return item;
            }
        }
        return null;
    }
}
